package xyz.yuanjilu.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import xyz.yuanjilu.dao.CarDao;
import xyz.yuanjilu.entity.CarEntity;
import xyz.yuanjilu.service.CarService;
import xyz.yuanjilu.utils.RRException;



@Service("carService")
public class CarServiceImpl implements CarService {
	@Autowired
	private CarDao carDao;
	
	@Override
	public CarEntity queryObject(Long id){
		return carDao.queryObject(id);
	}
	
	@Override
	public List<CarEntity> queryList(Map<String, Object> map){
		return carDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return carDao.queryTotal(map);
	}
	
	@Override
	public void save(CarEntity car){
		car.setCreateTime(new Date());
		String carPlateNumber = car.getCarPlateNumber();
		Map<String ,Object> param=new HashMap<String ,Object>();
		param.put("carPlateNumber", carPlateNumber);
		CarEntity queryCar = this.queryCar(param);
		if (queryCar!=null) {
			throw new RRException("车牌重复了");
		}
		carDao.save(car);
	}
	
	@Override
	public void update(CarEntity car){
		carDao.update(car);
	}
	
	@Override
	public void delete(Long id){
		carDao.delete(id);
	}
	
	@Override
	public void deleteBatch(Long[] ids){
		carDao.deleteBatch(ids);
	}

	@Override
	public CarEntity queryCar(Map<String, Object> map) {
		return carDao.queryCar(map);
	}
	
}
